package com.tsingtree.modular.service.impl;

import com.tsingtree.modular.entity.NanGiftActivity;
import com.tsingtree.modular.mapper.NanGiftActivityMapper;
import com.tsingtree.modular.model.params.NanGiftActivityParam;
import com.tsingtree.modular.model.result.NanGiftActivityResult;
import com.tsingtree.modular.service.NanGiftActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.tsingtree.base.pojo.page.LayuiPageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tsingtree.base.pojo.page.LayuiPageFactory;
import com.tsingtree.roses.core.util.ToolUtil;
import java.io.Serializable;

/**
 * <p>
 * 精美礼物-活动配置表 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2025-10-24
 */
@Service
public class NanGiftActivityServiceImpl extends ServiceImpl<NanGiftActivityMapper, NanGiftActivity> implements NanGiftActivityService {

    @Override
    public void add(NanGiftActivityParam param){
        NanGiftActivity entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(NanGiftActivityParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(NanGiftActivityParam param){
        NanGiftActivity oldEntity = getOldEntity(param);
        NanGiftActivity newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public NanGiftActivityResult findBySpec(NanGiftActivityParam param){
        return null;
    }

    @Override
    public List<NanGiftActivityResult> findListBySpec(NanGiftActivityParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(NanGiftActivityParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(NanGiftActivityParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private NanGiftActivity getOldEntity(NanGiftActivityParam param) {
        return this.getById(getKey(param));
    }

    private NanGiftActivity getEntity(NanGiftActivityParam param) {
        NanGiftActivity entity = new NanGiftActivity();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}

